package com.web.pay;

import com.github.wxpay.sdk.IWXPayDomain;
import com.github.wxpay.sdk.WXPayConfig;
import lombok.Cleanup;
import lombok.NonNull;
import lombok.SneakyThrows;

import java.io.*;

/**
 *
 * @author xukk
 * @date 2017/7/4
 */
public class WxPayConfigImpl extends WXPayConfig {

    private  String appID;
    private String mchID;
    private String key;
    private byte[] certData;
    @SneakyThrows(IOException.class)
    public WxPayConfigImpl(@NonNull String certPath) {
        File file = new File(certPath);
        @Cleanup  InputStream certStream = new FileInputStream(file);
        this.certData = new byte[(int) file.length()];
        certStream.read(this.certData);
    }

    public WxPayConfigImpl(String appId, String mchID, String key) {
        this.appID=appId;
        this.mchID=mchID;
        this.key=key;
    }
    @Override
    public String getAppID() {
        return appID;
    }

    @Override
    public String getMchID() {
        return mchID;
    }

    @Override
    public String getKey() {
        return key;
    }

    @Override
    public IWXPayDomain getWXPayDomain() {
        return WXPayDomainSimpleImpl.instance();
    }

    @Override
    public InputStream getCertStream(){
        ByteArrayInputStream certBis;
        certBis = new ByteArrayInputStream(this.certData);
        return certBis;
    }
    @Override
    public int getHttpConnectTimeoutMs() {
        return super.getHttpConnectTimeoutMs();
    }

    @Override
    public int getHttpReadTimeoutMs() {
        return super.getHttpReadTimeoutMs();
    }

    @Override
    public boolean shouldAutoReport() {
        return super.shouldAutoReport();
    }

    @Override
    public int getReportWorkerNum() {
        return super.getReportWorkerNum();
    }

    @Override
    public int getReportQueueMaxSize() {
        return super.getReportQueueMaxSize();
    }

    @Override
    public int getReportBatchSize() {
        return super.getReportBatchSize();
    }

}
